﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using System.IO;
using System.Windows.Controls.DataVisualization.Charting;
using System.Collections;
using System.Windows.Controls.DataVisualization;

using System.ComponentModel;
using ActivityTracker.Library;
using Common.Library;

namespace ActivityTracker
{
    public partial class Monthly_ProgressBarChart : PhoneApplicationPage
    {
        #region global

        Actvity objActivity = new Actvity();
        MonthlyChart objMonthlyChart = new MonthlyChart();
        string actId = "";
        string actStartDate = "";

        #endregion

        #region constructor

        public Monthly_ProgressBarChart()
        {
            InitializeComponent();
            BarChart.LegendStyle = ChartLegendStyles.hidelegend();
            BarChart.Visibility = Visibility.Collapsed;
        }

        #endregion

        #region Page events

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                NavigationContext.QueryString.TryGetValue("actId", out actId);
                NavigationContext.QueryString.TryGetValue("actStartDate", out actStartDate);
                LoadChart();
            }
            catch (Exception ex)
            {
                string mess = "Exception in PhoneApplicationPage_Loaded Method In Monthly_ProgressBarChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void btnPieChartt_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Charts/Monthly/Monthly_ProgressPieChart.xaml?actId=" + actId + "&actStartDate=" + actStartDate, UriKind.Relative));
        }

        #endregion

        #region CustomMethods

        private void LoadChart()
        {
            try
            {
                List<ChartProp> objChartList = objMonthlyChart.LoadProgressData(actId, actStartDate);
                if (objChartList.Count > 0)
                    ContentPanel.DataContext = objChartList;
                BarChart.Title = objActivity.GetActivityName(actId).ToUpper();
                BarChart.Style = Application.Current.Resources["PhoneChartStyle"] as Style;
                //Dynamically adjusting the height of chart
                BarChart.MinHeight = 600;
                BarChart.Height = (objChartList.Count * 50) + 50;
                BarSeries b = (BarSeries)BarChart.Series[0];
                CategoryAxis ca = new CategoryAxis();
                ca.Height = objChartList.Count * 50;
                b.IndependentAxis.DependentAxes.Add(ca);
                BarChart.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in LoadChart Method In Monthly_ProgressBarChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace);
                throw exnew;
            }
        }

        #endregion
    }
}